package com.clps.algorithm.chapter14.最长斐波那契数列;

import java.util.HashMap;
import java.util.Map;

public class demo01 {

    public static void main(String[] args) {

    }

    public int lenLongestFibSubSeq(int[] A){
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i <A.length ; i++) {
            map.put(A[i],i);
        }

        int[][] dp = new int[A.length][A.length];
        int result = 2;
        for (int i = 0; i < A.length; i++) {
            for (int j = 0; j < i; j++) {
                int k = map.getOrDefault(A[i] - A[j],-1);
                dp[i][j] = k >=0 && k<j?dp[i][j]+1:2;
                result = Math.max(result,dp[i][j]);
            }
        }

        return  result>2?result:0;
    }
}
